<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<base href="<%=basePath%>" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>部门表单</title>
		<link rel="stylesheet" href="res/layui/css/layui.css">
		<script src="res/js/jquery-2.1.4.min.js" type="text/javascript"></script>
		<script src="res/layui/layui.js"></script>
	</head>
	<body style="padding: 40px 40px 0px 40px">
		<form class="layui-form" id="department">
			<input type="hidden" id="departId" name="departId">
			<div class="layui-form-item">
				<label class="layui-form-label">部门编码</label>
				<div class="layui-input-block">
					<input type="text" id="departNumber" name="departNumber" lay-verify="required"
						autocomplete="off" placeholder="请输入部门编码" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">部门名称</label>
				<div class="layui-input-block">
					<input type="text" id="departName" name="departName" lay-verify="required"
						placeholder="请输入部门名称" autocomplete="off" class="layui-input">
				</div>
			</div>
	
			<div class="layui-form-item">
				<label class="layui-form-label">部门性质</label>
				<div class="layui-input-block">
					<input type="text" id="departKind" name="departKind" lay-verify="required"
						placeholder="请输入部门性质" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-form-item layui-form-text">
				    <label class="layui-form-label">备注</label>
				    <div class="layui-input-block">
				      <textarea placeholder="请输入内容" class="layui-textarea" id="departRemark" name="departRemark"></textarea>
				    </div>
				</div>
			</div>
			<input type="hidden" id="departBy" name="departBy" value="${staff.staffName }">
			<div class="layui-input-block">
		        <button class="layui-btn" lay-submit lay-filter="demo">立即提交</button>
		        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		    </div>
		</form>
		
		<script type="text/javascript">
			var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
			
			var departId;
			
			$(function (){
				departId = GetQueryString("departId");
				if(departId!=null){
					findById(departId);
				}
			});
			
			var form;
			layui.use(['form'], function() {
				form = layui.form;
				//监听提交
				form.on('submit(demo)', function(data){
					var data = $("#department").serialize();
					var url = "department/addOrUpdate.action";
					var loadIndex = layer.load();
					$.post(url, data, function(mes){
						parent.layer.msg(mes.mes);
						
						layer.close(loadIndex);//加载层关闭  
						parent.layer.close(index);
						if($("#departId").val()!=""){
							$(".layui-laypage-skip .layui-laypage-btn",window.parent.document).click();//刷新父页面数据表格的当前页
						}else{
							parent.table.reload('departId');
						}

					});
					return false;
				});
				
			});
			
			function findById(departId){
				$.ajax({
					type: "POST",
					url: "department/findById.action",
					data: {"departId":departId},
					async: false,
					error: function(){
						layer.mes("发生未知错误，请稍后再试！");
					},
					success: function(obj){
						$("#departId").val(obj.departId);
						$("#departKind").val(obj.departKind);
						$("#departName").val(obj.departName);
						$("#departNumber").val(obj.departNumber);
						$("#departRemark").val(obj.departRemark);
					}
				});
			}
			
			/**
			得到URL栏的参数
			*/
			function GetQueryString(name){
			     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
			     var r = window.location.search.substr(1).match(reg);
			     if(r!=null)return  unescape(r[2]); return null;
			}
		</script>
	</body>
</html>